<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>

<body>
    <script>
        function Person(name) {
            this.name = name;
        }
        var p1 = Person('刘德华');
        function creatrPerson(name) {
            var isBool = true;
            return {
                setName:function(name){
                    this.name = name;
                },
                getName:function(name){
                    return this.name;
                },
                setSex:function(sex){
                    if(isBool){
                        isBool = false;
                        this.sex = sex;
                    }else {
                        console.log('性别只允许修改一次');
                        
                    }
                },
                getSex:function (){
                    return this.sex;
                }
            }
        }
        var p2 = creatrPerson();
        p2.setName('张学友');
        console.log(p2.getName());
        p2.setSex('女');
        console.log(p2.getSex());
        p2.setSex('男');
        console.log(p2.getSex());
        
    </script>
</body>

</html>